#ifndef DEVICEMANAGEMENT_H
#define DEVICEMANAGEMENT_H

#include <QObject>
#include <QSqlDatabase>
#include <QSqlRecord>
#include <QList>
#include <QMutex>

class DeviceManagement : public QObject
{
    Q_OBJECT
public:
    explicit DeviceManagement(QObject *parent = nullptr);
    ~DeviceManagement();

    // 获取最后一次操作的错误信息
    QString getLastError() const;

    // 创建设备表
    void createDeviceTable();

    // 设备管理操作
    bool addDevice(const QString& name, const QString& type, const QString& location,
                   const QString& manufacturer, const QString& model, const QString& installationDate);
    bool deleteDevice(int deviceId);
    bool updateDevice(int deviceId, const QString& name, const QString& type, const QString& status);
    QList<QSqlRecord> getDevicesByType(const QString& type);
    QList<QSqlRecord> getDevicesByLocation(const QString& location);
    bool deviceExists(int deviceId); // 设备存在性检查

private:
    QString m_lastError;
    QMutex m_mutex;
};

#endif // DEVICEMANAGEMENT_H
